package auctionhaus



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
 */
@TestFor(BidController)
@Mock([Listing, Customer, Bid])
class BidControllerTests {
    def listing1
    def seller
    def bid

    public void startup() {
        seller = new Customer(email: "johndoe@acme.com", password: "asdfqw")
        seller.save(flush: true)

        listing1 = new Listing(id: 1, name: "listing 1", endTime: new Date()+1, startBid: 5, seller: seller)
        listing1.save(flush: true)
    }

    void testSomething() {
        mockDomain(Customer)
        mockDomain(Listing)
        mockDomain(Bid)

        seller = new Customer(email: "johndoe@acme.com", password: "asdfqw")
        seller.save(flush: true)

        listing1 = new Listing(id: 1, name: "listing 1", endTime: new Date()+1, startBid: 5, seller: seller)
        listing1.save(flush: true)
        
        bid = new Bid(amount: 2, bidder: seller, listing: listing1)
        bid.save(flush: true)

        def controller = new BidController()
        controller.params.amount = bid.amount
        controller.params.put("listing.id", listing1.id)
        controller.params.put("seller.id", seller.id)
        controller.save()

        assert controller.response.redirectUrl.equalsIgnoreCase("/listing/show/1")
        assert flash.message.toString().contains("Your bid was invalid for the following reasons:")
    }

    public void tearDown() {
        seller = null
        listing1 = null
    }
}
